package lucasapp.CentralStation_PRO;

import java.util.ArrayList;

import android.appwidget.AppWidgetManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class WidgetBroadcastReceiver extends BroadcastReceiver {
	/**
	 * A BroadcastReceiver that listens for updates for the ExampleAppWidgetProvider.  This
	 * BroadcastReceiver starts off disabled, and we only enable it when there is a widget
	 * instance created, in order to only receive notifications when we need them.
	 */

	@Override
	public void onReceive(Context context, Intent intent) {
		Log.d("BroadcastReceiver", "intent=" + intent);

		// For our example, we'll also update all of the widgets when the timezone changes, or the user or network sets the time.
		String action = intent.getAction();
		if (action.equals(Intent.ACTION_TIMEZONE_CHANGED) || action.equals(Intent.ACTION_TIME_CHANGED)) {
			AppWidgetManager gm = AppWidgetManager.getInstance(context);
			ArrayList<Integer> appWidgetIds = new ArrayList<Integer>();
			ArrayList<String> texts = new ArrayList<String>();

			WidgetConfigure.loadAllTitlePrefs(context, appWidgetIds, texts);
			final int N = appWidgetIds.size();
			for (int i=0; i<N; i++) {
				WidgetProvider.updateAppWidget(context, gm, appWidgetIds.get(i), texts.get(i));
			}
		}
	}
}